﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Rison.DataAccess.Data.ZJCP;

namespace Rison.Web.ZJCP.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class load_illustrativecase : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
             context.Response.ContentType = "text/plain";
             string ilId = context.Request.Params["ilId"];
             if (String.IsNullOrEmpty(ilId))
            {
                context.Response.Write("false");
            }
            else
            {
                context.Response.Write(loadIllustrativecase(ilId));
            }
           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string loadIllustrativecase(string ilId)
        {
            string sql = String.Format("select il_case_num, il_case_time, il_case_reason, il_case_result, il_last_save_time from Illustrativecase where il_id='{0}'", ilId);
            DataSet ds = DbAccess.executeQuery(sql);
            string caseNum = ds.Tables[0].Rows[0][0].ToString();
            string caseTime = ds.Tables[0].Rows[0][1].ToString();
            string caseReason = ds.Tables[0].Rows[0][2].ToString();
            string caseResult = ds.Tables[0].Rows[0][3].ToString();
            string lastSaveTime = ds.Tables[0].Rows[0][4].ToString();
            caseNum = replaceSpicalCharacter(caseNum);
            caseTime = replaceSpicalCharacter(caseTime);
            caseReason = replaceSpicalCharacter(caseReason);
            caseResult = replaceSpicalCharacter(caseResult);
            lastSaveTime = replaceSpicalCharacter(lastSaveTime);
            return String.Format("{{caseNum:\"{0}\",caseTime:\"{1}\",caseReason:\"{2}\",caseResult:\"{3}\", lastSaveTime:\"{4}\"}}", caseNum, caseTime, caseReason, caseResult, lastSaveTime).ToString();

        }
        private string replaceSpicalCharacter(string str)
        {
            if (!String.IsNullOrEmpty(str))
            {
                str = str.Replace("\n", "\\n");
                str = str.Replace("\r", "\\r");
                str = str.Replace("\"", "\\\"");
            }
            return str;
        }
    }
}
